package org.pvs.superpalitos.sp_lite.gui;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JPanel;

import org.pvs.superpalitos.sp_lite.SuperPalitos;
import org.pvs.superpalitos.sp_lite.util.ColorUtil;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import java.awt.Font;

public class PrePartidaPanel extends JPanel {
	private int color = ColorUtil.COLOR_DEFECTO;
	private int dificultad = SuperPalitos.DIFICULTAD_DEFECTO;
	
	public PrePartidaPanel() {
		setOpaque(false);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 220, 10, 0};
		gridBagLayout.rowHeights = new int[]{10, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, 0.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{1.0, 0.0, 1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JPanel panel = new JPanel();
		panel.setOpaque(false);
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(0, 0, 5, 5);
		gbc_panel.anchor = GridBagConstraints.NORTH;
		gbc_panel.gridx = 1;
		gbc_panel.gridy = 1;
		add(panel, gbc_panel);
		panel.setLayout(new BorderLayout(0, 0));
		
		JPanel panel_2 = new JPanel();
		panel_2.setOpaque(false);
		panel.add(panel_2, BorderLayout.CENTER);
		panel_2.setLayout(new GridLayout(2, 2, 5, 5));
		
		JLabel lblDificultad = new JLabel("Dificultad");
		panel_2.add(lblDificultad);
		
		jComboBox2 = new javax.swing.JComboBox(SuperPalitos.DIFICULTADES);
		panel_2.add(jComboBox2);
		
		JLabel lblColor = new JLabel("Color");
		panel_2.add(lblColor);
		
		jComboBox1 = new ColorBox(ColorUtil.getColors());
		panel_2.add(jComboBox1);
		
		JPanel panel_1 = new JPanel();
		panel_1.setOpaque(false);
		FlowLayout flowLayout = (FlowLayout) panel_1.getLayout();
		flowLayout.setVgap(10);
		flowLayout.setAlignment(FlowLayout.RIGHT);
		panel.add(panel_1, BorderLayout.SOUTH);
		
		JButton button = new JButton("<<");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SuperPalitos.getInstance().back();
			}
		});
		panel_1.add(button);
		
		JButton btnJugar = new JButton("Jugar");
		btnJugar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
	    	color = jComboBox1.getSelectedIndex();
	    	dificultad = jComboBox2.getSelectedIndex();
	      SuperPalitos.getInstance().play(dificultad, color);
			}
		});
		btnJugar.setFont(new Font("Dialog", Font.BOLD, 14));
		panel_1.add(btnJugar);
		
		setPreferredSize(SuperPalitos.SIZE);
    jComboBox2.setSelectedIndex(dificultad);
    jComboBox1.setSelectedIndex(color);
	}
	private static final long serialVersionUID = 13120027966037280L;

	
  private static final String IMAGE_FILE = "/icons/title.png";
  private static final Image FONDO = Toolkit.getDefaultToolkit().getImage(TableroPanel.class.getResource(IMAGE_FILE));
  private JComboBox jComboBox2;
  private JComboBox jComboBox1;
  @Override
  public void paintComponent(Graphics g) {
  	super.paintComponent(g);
  	Graphics g2 = g.create();
    g2.drawImage(FONDO, 0, 0, null);
  }
	protected JComboBox getJComboBox2() {
		return jComboBox2;
	}
	protected JComboBox getJComboBox1() {
		return jComboBox1;
	}
}
